package com.liesheng.haylou.utils;

import android.app.Activity;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;

/**
 * Date:2019/11/7
 * <p>
 * Author:wuzhiguang
 * <p>
 * Description:
 */
public class ImmersiveStatusBarUtil {
    public static boolean supportedImmersiveStatusBar() {
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
    }

    public static void initImmersiveStatusBarActivity(Activity activity) {
        if (supportedImmersiveStatusBar()) {

            View decorView = activity.getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
            decorView.setSystemUiVisibility(option);

            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
                setStatusBarColor(activity, Color.TRANSPARENT);
            } else {
                setStatusBarColor(activity, Color.BLACK);
            }
        }
    }

    public static void setStatusBarColor(Activity activity, int color) {
        activity.getWindow().setStatusBarColor(color);
    }

//    public static void initImmersiveStatusBarView(View view) {
//        if (supportedImmersiveStatusBar()) {
//            View v = view.findViewById(R.id.immersive_status_bar_view);
//            if (v == null) {
//                v = view;
//            }
//            ViewGroup.LayoutParams lp = v.getLayoutParams();
//            lp.height = getStatusBarHeight();
//            v.setVisibility(View.VISIBLE);
//        }
//    }

    public static int getStatusBarHeight() {
        int resourceId = Resources.getSystem().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            return Resources.getSystem().getDimensionPixelSize(resourceId);
        }
        return 0;
    }
}
